#include<bits/stdc++.h>
using namespace std;
long long a[200010],c[200010],T,n,ans;
inline void run(long long dep,long long color,long long sum){
    if(dep>n){
        ans=max(ans,sum);
        return;
    }
    long long s=0;
    for(long long i=dep-1;i>=1;--i)
        if(c[i]==color){
            if(a[i]==a[dep]) s+=a[i];
            break;
        }
    c[dep]=color;
    run(dep+1,0,sum+s);
    run(dep+1,1,sum+s);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>T;
    while(T--){
        cin>>n;
        for(long long i=1;i<=n;++i)
            cin>>a[i];
        ans=INT_MIN;
        run(1,0,0);
        run(1,1,0);
        cout<<ans<<"\n";
    }
    return 0;
}